<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{baseui/head :: head}">
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta name="description" content="动检通智慧云平台"/>
    <meta name="author" content="牧中(上海)物联网科技有限公司"/>
    <link rel="shortcut icon" href="/webjars/images/favicon.png"/>
    <link rel="stylesheet" href="/webjars/js/layui/css/layui.css"  media="all">
    <title>牧中畜牧业大数据智慧云平台V1.0</title>


</head>
<body>
<!--顶部一级导航-->
<th:block  th:replace="baseui/topheader :: topheader(1)"/>

<!--动检通菜单-->
<th:block  th:replace="djt/partial/topnav :: topnav(2)" />


<div id="cl-wrapper">
    <!--左边导航-->
    <th:block th:replace="djt/partial/prod_left :: nav(6)" />

    <div class="container-fluid" id="pcont">
        <!--<div class="page-head">-->
        <!--<h3>生产记录</h3>-->
        <!--</div>-->


        <div class="row">
            <div class="col-md-12">
                <div class="block-flat">
                    <div class="header"><h3>消毒记录</h3></div>
                    <div class="content">
                        <div class="table-responsive">
                            <div id="datatable_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">


                                <div class="row">

                                    <!-- search-->

                                    <div  style="white-space: nowrap">

                                        <div class="col-sm-2">
                                            <div class="input-group date datetime col-md-5 col-xs-7"
                                                 data-min-view="2" data-date-format="yyyy-mm-dd">
                                                <input id="start" class="form-control" style="width: 90px;" size="16"
                                                       type="text" value="" placeholder="开始时间" readonly>
                                                <span class="input-group-addon btn btn-primary"><span
                                                        class="glyphicon glyphicon-th"></span></span>
                                            </div>
                                        </div>
                                        <div class="col-sm-2">
                                            <div class="input-group date datetime col-md-5 col-xs-7"
                                                 data-min-view="2" data-date-format="yyyy-mm-dd">
                                                <input id="end" class="form-control" style="width: 90px;" size="16"
                                                       type="text" value="" placeholder="结束时间" readonly>
                                                <span class="input-group-addon btn btn-primary"><span
                                                        class="glyphicon glyphicon-th"></span></span>
                                            </div>


                                        </div>

                                        <span style="margin-left: 30px">   区域:
                                                           <select class="select2" style="max-width: 100px;" onchange="showfactory()" id="city">
                                                           <option value="全部" >所有区域</option>
                                                               <span th:each="cityAreaDto :${cityAreaDtoList}">
                                                            <optgroup  th:label="${cityAreaDto.city}" >
                                                                <span th:each="region :${cityAreaDto.regions}">
                                                            <option th:value="${region}" th:text="${region}">南漳县</option>
                                                                    </span>
                                                          </optgroup>
                                                                   </span>
                                                                 </select>

                                            </span>
                                        <span style="margin-left: 30px">   养殖场:


                                                           <select class="select2" style="max-width: 165px;"
                                                                   id="factory">

                                                                       <option value='-1' selected>所有养殖场</option>
                                                                    <span th:each=" breedFactory :${breedFactoryList}">
                                                                  <option th:text="${breedFactory.name}"
                                                                          th:value="${breedFactory.id}">选项 1</option>

                                                                   </span>


                                                       </select>

                                                         </span>


                                        <span style="margin-left: 30px;display: none" >   畜种:
                                                           <select class="select2" style="max-width: 100px;"  id="breedType">
                                                               <option value="-1" >全部</option>
                                                               <option value="1">猪 </option>
                                                               <option value="2">牛 </option>
                                                               <option value="3">羊 </option>
                                                               <option value="4">家禽</option>

                                                                 </select>

                                            </span>
                                        <span style="margin-left: 30px">
                                        药品名称：<input placeholder="名字"
                                               class="form-control layer-date"
                                               id="drugName"/>
                                        </span>

                                        <span style="margin-left: 30px">
                                                <button class="btn btn-primary" onclick="SearchBtn()">搜索</button>
                                                </span>

                                    </div>


                                    <!--
                                                                            <div class="col-sm-6">
                                                                            <div id="datatable_filter" class="dataTables_filter">
                                                                            <label>区域:<select class="select2">
                                                                                <option value="所有区域">所有区域</option>
                                                                                <optgroup label="襄阳市">
                                                                                    <option value="南漳县">南漳县</option>
                                                                                    <option value="其它县">其它县</option>
                                                                                </optgroup>
                                                                            </select>


                                                                            </label></div>
                                                                            </div>
                                                                        </div>
                                    -->
                                    <div class="row">
                                        <div class="col-sm-12">

                                            <!-- Table -->
                                            <table id="jqGrid"></table>
                                            <div id="jqGridPager"></div>

                                        </div>
                                    </div>


                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>









        </div>
    </div>

</div>

<script type="text/javascript" src="/webjars/js/jquery.js"></script>

<script type="text/javascript" src="/webjars/js/jquery.nanoscroller/jquery.nanoscroller.js"></script>
<script type="text/javascript" src="/webjars/js/behaviour/general.js"></script>
<script src="/webjars/js/jquery.ui/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript" src="/webjars/js/jquery.nestable/jquery.nestable.js"></script>

<script type="text/javascript" src="/webjars/js/bootstrap.switch/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="/webjars/js/jquery.select2/select2.min.js" type="text/javascript"></script>

<script src="/webjars/js/bootstrap.slider/js/bootstrap-slider.js" type="text/javascript"></script>
<script type="text/javascript" src="/webjars/js/jquery.niftymodals/js/jquery.modalEffects.js"></script>
<script type="text/javascript" src="/webjars/js/bootstrap.summernote/dist/summernote.min.js"></script>




<script type="text/javascript" src="/webjars/js/jquery.magnific-popup/dist/jquery.magnific-popup.min.js"></script>



<script src="/webjars/js/behaviour/voice-commands.js"></script>
<script src="/webjars/js/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/ecmascript" src="/webjars/jqgrid/js/i18n/grid.locale-cn.js"></script>
<script type="text/ecmascript" src="/webjars/jqgrid/js/jquery.jqGrid.min.js"></script>

<script src="/webjars/js/layui/layui.js" charset="utf-8"></script>


<script type="text/javascript">
    var PostDatas = {breedFactoryId:factoryoption()};
    $(document).ready(function(){

        App.init();

        //grid
        $("#jqGrid").jqGrid({
            url: '/djt/breedarch/disinfectReport/select',
            postData:PostDatas,
            mtype: "post",
            styleUI : 'Bootstrap',
            datatype: "json",
            autowidth: true,
            shrinkToFit:true,
            colModel: [
                { label: '<span style="text-align: center">序号</span>', name: 'id', key: true, width: 75, align:'center'},
                { label: '<span style="text-align: center">养殖场名称</span>', name: 'breedFactoryName', width: 200 , align:'center'},
                { label: '<span style="text-align: center">药品</span>', name: 'drugName', width: 100, align:'center'},
                { label:'<span style="text-align: center">用药量</span>', name: 'drugUsedQuantity', width: 100, align:'center'},
                { label:'<span style="text-align: center">消毒方式</span>', name: 'disinfectMethod', width: 100, formatter:ShowMethod,align:'center'},
                { label:'<span style="text-align: center">单位</span>', name: 'drugUsedUnit', width: 100, formatter:Showunit,align:'center'},
                { label:'<span style="text-align: center">日期</span>', name: 'date', width: 200 ,formatter:ShowDate, align:'center'},
                { label:'<span style="text-align: center">详细</span>', name: 'deathQuantity', width: 200, align:'center',formatter:ShowOpertator}
            ],
            viewrecords: true,
            height: 350,

            rowNum: 20,
            pager: "#jqGridPager"
        });

    });

    function city() {

        var city = $("#city").val();


        if (city =="全部") {
            var array1 = new Array();
            $("#city option").each(function () {  //遍历所有option
                var txt = $(this).val();   //获取option值
                if (txt != '') {
                    array1.push(txt);  //添加到数组中
                }
            });

            return array1.toString();
        }else {
            var array2 = new Array();
            array2.push(city);
            return array2.toString();
        }

    }

    function showfactory() {




        var type = $("#breedType").val();

        $.ajax({

            url: "/djt/breedarch/search",
            data: {region: city(), breedType: type},
            dataType: "json",
            success: function (data) {

                $("#factory").empty();

                if (data.length != 0) {
                    var str1 = " <option value='-1' selected>所有养殖场</option>";
                    $("#factory").append(str1);
                    $.each(data, function (index, obj) {
                        var id = obj.id;
                        var name = obj.name;
                        var str = "<option value=" + id + ">" + name + "</option>";

                        $("#factory").append(str);
                    });
                } else {

                    var str = "<option value='0' selected>无</option>";
                    $("#factory").append(str);
                }
            }
        });
    }
    function factoryoption() {

        var factory_id = $("#factory").val();


        if (factory_id == -1) {
            var array1 = new Array();
            $("#factory option").each(function () {  //遍历所有option
                var txt = $(this).val();   //获取option值
                if (txt != '') {
                    array1.push(txt);  //添加到数组中
                }
            });

            return array1.toString();
        } else if (factory_id == 0) {
            var array3 = new Array();
            array3.push(factory_id);
            return array3.toString();

        } else {
            var array2 = new Array();
            array2.push(factory_id);
            return array2.toString();
        }

    }
    // 搜索
    var SearchBtn = function()
    {
        var time1 =$("#start").val();
        var time2=$("#end").val();
        if(time1==""){
            time1 = new Date("2000-01-01 :00:00:00");
        }else{
            time1 = new Date(time1);
        }

        if(time2==""){
            time2=new Date();
        }else{
            time2 = new Date(time2);
        }
        var breedType=$("#breedType").val();
        var drugName=$("#drugName").val();
        var sdata = {   // 构建查询需要的参数
            drugName :drugName,
            breedType:breedType,
            breedFactoryId:factoryoption(),
            time1 :time1,
            time2 :time2
        };


        var postData = $("#jqGrid").jqGrid("getGridParam", "postData");

        $.extend(postData, sdata);

        $("#jqGrid").jqGrid("setGridParam", {
            search: true    // (6)将jqGrid的search选项设为true
        }).trigger("reloadGrid", [{page:1}]);   // (7)重新载入Grid表格，以使上述设置生效

    }
    //    时间格式化
    function ShowDate(cellvalue, options, rowObject) {

        var timestamp4 = new Date(cellvalue);
        var dt= timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
        return dt;
    }
    //消毒方式
    function ShowMethod(cellvalue, options, rowObject) {
        var  type;
        switch (cellvalue){
            case 1:
                type="喷雾";
                break;
            case 2:
                type="其它";
                break;

        }
        return type;
    }

    //查看

    function ShowOpertator(cellvalue, options, rowObject)
    {
        var link;
        var rowval = rowObject["id"];

        var row =JSON.stringify(rowObject);

        link = "<button type='button' class='btn btn-default' id='" + row + "' onclick='select(this.id)'>查看</button><button type='button' class='btn btn-default' id='" + row + "' onclick='delete1(this.id)'>删除</button>";
        return link;
    }

    //单位
    function Showunit(cellvalue, options, rowObject) {
        var  type;
        switch (cellvalue){
            case 1:
                type="头";
                break;
            case 2:
                type="只";
                break;
            case 3:
                type="羽";
                break;
            case 4:
                type="克";
                break;
            case 5:
                type="毫升";
                break;
            case 6:
                type="头份";
                break;
            case 7:
                type="kg";
                break;
        }
        return type;
    }

    function getarea(a) {

        var type;
        switch (a) {
            case 1:
                type = "繁殖区";
                break;
            case 2:
                type = "保育区";
                break;
            case 3:
                type = "育肥区";
                break;
        }
        return type;
    }

    function select (data) {


        var json = JSON.parse(data);
        var area=getarea(json.area);
        var timestamp4 = new Date(json.date);
        var dt= timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8);
       var disinfectMethod=ShowMethod(json.disinfectMethod,null,null);
        layui.use(['laypage', 'layer'], function() {
            var $ = layui.jquery, layer = layui.layer;


            layer.open({
                type: 2,
                skin:'layui-layer-lan',
                area: ['800px', '600px'],
                content: ['/djt/breedarch/disinfectReportdetail','no'],
                success: function(layero, index){
                    var body = layer.getChildFrame('body', index);
                    var iframeWin = window[layero.find('iframe')[0]['name']];

                    body.find("#breedFactoryName").text(json.breedFactoryName);
                    body.find("#number").text(json.number);
                    body.find("#area").text(area);
                    body.find("#stableNumber").text(json.stableNumber);

                    body.find("#date").text(dt);
                    body.find("#drugName").text(json.drugName);
                    body.find("#drugUsedQuantity").text(json.drugUsedQuantity);

                    body.find("#disinfectMethod").text(disinfectMethod);



                    var tt=json.drug;


                    for (var key in tt){
                        if (tt[key]!=null){
                            var a = "<img src="+tt[key]['uri']+" class='img-thumbnail' layer-src="+tt[key]['uri']+" style='width: 150px;height: 200px' onclick='showimg(this)'>";
                            if (tt[key]['uri']!=null&&tt[key]['uri']!=""){
                                body.find("#drugPhoto").append(a);
                            }
                        }


                    }





                }
            });


        });
    }



    function delete1(data) {
        var json = JSON.parse(data);
        layui.use(['laypage', 'layer'], function () {
            var $ = layui.jquery, layer = layui.layer;


            layer.msg('确定删除吗？', {
                time: 60000, //20s后自动关闭
                btn: ['确定', '取消'],
                btnAlign: 'c',
                btn1: function (index, layero) {

                    $.ajax({

                        url: "/djt/breedarch/disinfectDelete",
                        data: {
                            id: json.id,

                        },
                        dataType: "json",
                        success: function (data) {
                            if (data) {
                                layer.msg('删除成功', {
                                    time: 60000, //20s后自动关闭
                                    btn: '确定',
                                    btnAlign: 'c',
                                    btn1: function (index, layero) {
                                        window.location.href ="/djt/breedarch/disinfectReport";
                                    }
                                })

                            }else {
                                layer.msg('删除失败请重试', {
                                    time: 60000, //20s后自动关闭
                                    btn: '确定',
                                    btnAlign: 'c',
                                    btn1: function (index, layero) {
                                        window.location.href ="/djt/breedarch/disinfectReport";
                                    }
                                })
                            }
                        }
                    })
                }

            })


        });

    }

</script>

<script src="/webjars/js/laydate/laydate.js"></script>

</body>
</html>
